/**
 * 
 */
package com.honghao.student.util;

import java.io.IOException;

import javax.servlet.ServletContext;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.ServletContextAware;

import com.honghao.student.constans.StudentConstans;

/**
 * @author honghao.li
 */
public class ResourcePathExposer implements ServletContextAware {

	private static final Logger LOGGER = LoggerFactory
			.getLogger(ResourcePathExposer.class);

	@Getter
	private ServletContext servletContext;

	@Getter
	private String resourceRoot;

	private static String VERSION;

	static {
		try {
			VERSION = CommonUtils.getValue4Pro("systemconfig.properties",
					StudentConstans.SINGLEPRO, new String[] { "version" }).get(
					0);
		} catch (IOException e) {
			LOGGER.error("systemconfig.properties not found");
		}
	}

	public void init() {
	    resourceRoot = "/resources-" + VERSION;
		getServletContext().setAttribute("resourceRoot",
				getServletContext().getContextPath() + resourceRoot);
		if(LOGGER.isDebugEnabled())
		LOGGER.debug("static resources"+getServletContext().getContextPath()+resourceRoot);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.web.context.ServletContextAware#setServletContext
	 * (javax.servlet.ServletContext)
	 */
	@Override
	public void setServletContext(ServletContext servletContext) {
		this.servletContext = servletContext;
	}

}
